<template>
  <div class="guns-body">
    <!-- 搜索表单 -->
    <div class="block-interval">
      <a-card :bordered="false">
        <a-form layout="inline" :model="where">
          <a-row>

            <a-form-item label="举报理由:">
              <a-input v-model:value.trim="where.tipOffReason" placeholder="智能体ID" allow-clear />
            </a-form-item>

            <a-form-item label="智能体ID:">
              <a-input v-model:value.trim="where.agentNo" placeholder="智能体ID" allow-clear />
            </a-form-item>

            <a-form-item label="用户ID:">
              <a-input v-model:value.trim="where.custNo" placeholder="用户ID" allow-clear />
            </a-form-item>

            <a-form-item class="ele-text-center">
              <a-space>
                <a-button type="primary" @click="reload">查询</a-button>
                <a-button @click="reset">重置</a-button>
              </a-space>
            </a-form-item>
          </a-row>
        </a-form>
      </a-card>
    </div>

    <!-- 表格 -->
    <div>
      <a-card :bordered="false" class="table-height">
        <BasicTable :canResize="false" ref="tableRef" :api="() => TipOffApi.findPage(where)" :where="where"
          :columns="columns" showTableSetting rowKey="agentNo" :rowSelection="{
        type: 'checkbox',
        selectedRowKeys: checkedKeys,
      }">
          <!-- table上边工具栏 -->
          <template #toolbar>
            <div class="table-toolbar"> </div>
          </template>

          <template #bodyCell="{ column, record }">

            <!-- N：待审核 -->
            <template v-if="column.key === 'status' && record.checkResult === '0'">
              <a @click="approve(record)">审批</a>
            </template>

            <template v-if="column.dataIndex == 'nickName'">
              <a @click="openDetail(record)">{{ record.nickName }}</a>
            </template>


          </template>
        </BasicTable>
      </a-card>
    </div>

    <!-- 通过弹窗 -->
    <a-modal v-model:visible="visible" title="审批驳回" @ok="handleOk(record)">
      <a-radio-group v-model:value="statusOne" default-value="1">
        <a-radio value="1">通过</a-radio>
        <a-radio value="2">驳回</a-radio>
      </a-radio-group>
    </a-modal>
    <!-- 操作日志详情 -->
    <ai-agent-detail v-model:visible="showDetail" :detail="current" />
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { BasicTable } from '/@/components/Table';
import { message } from 'ant-design-vue';
import { TipOffApi } from '/@/api/touch/tipOff/TipOffApi';
import { AiAgentApi } from '/@/api/touch/aiAgent/AiAgentApi';
import AiAgentDetail from '/@/views/touch/aiAgentCheck/aiAgent-detail.vue';

// 查询条件
const where = reactive({
  beginTime: '',
  endTime: '',
  nickName: '',
  custNo: '',
  agentNo: ''
});

const options = ref<SelectProps['options']>([
  {
    value: '',
    label: '请选择',
  },
  {
    value: 'N',
    label: '待审核',
  },
  {
    value: 'Y',
    label: '通过',
  },
]);



// 表格配置
const columns = ref<string[]>([
  // {
  //   title: '编号',
  //   dataIndex: 'id',
  // },
  {
    title: '创建时间',
    dataIndex: 'createTime',
  },
  {
    title: '创建用户ID',
    dataIndex: 'custNo',
  },
  {
    title: '智能体ID',
    dataIndex: 'agentNo',
  },
  {
    title: '智能体人设详情',
    dataIndex: 'nickName',
  },
  {
    title: '举报分类',
    dataIndex: 'tipOffType',
    customRender: function ({ text }) {
      if ('001' === text) {
        return '色情低俗';
      } else if ('002' === text) {
        return '政治敏感';
      } else if ('003' === text) {
        return '血腥暴力';
      } else if ('004' === text) {
        return '违法违规';
      } else if ('005' === text) {
        return '仇恨骚扰';
      } else if ('006' === text) {
        return '辱骂攻击';
      } else if ('007' === text) {
        return '抄袭侵权';
      } else {
        return '其它有害信息';
      }
    }
  },
  {
    title: '举报理由',
    dataIndex: 'tipOffReason',
  },
  {
    title: '审核时间',
    dataIndex: 'checkDate',
  },
  {
    title: '审核结果',
    dataIndex: 'checkResult',
    customRender: function ({ text }) {
      if ('0' === text) {
        return '未处理';
      } else if ('1' === text) {
        return '举报成功';
      } else {
        return '举报失败';
      }
    }
  },
  {
    title: '审核人',
    dataIndex: 'realName',
  },
  {
    title: '操作',
    dataIndex: 'status',
    align: 'center',
  },
]);
const visible = ref<boolean>(false);
let approval = ref<string>('');
let record = ref<any>({});
let statusOne = ref<string>('1');
/**
 * 审批
 *
 */
const approve = async (row: any) => {
  // const agentNo = row.agentNo;
  record = { ...row };
  visible.value = true;
};


const handleOk = async (row: any) => {
  const id = record.id;
  const checkResult = statusOne.value;
  visible.value = false;
  let result = await TipOffApi.updateStatus({
    id,
    checkResult
  });
  console.log(result);
  message.success(result.message);
  reload();
};

// 多选选中列表
const checkedKeys = ref<Array<string | number>>([]);

// 当前行数据
const current = ref<any>(null);

// 是否显示详情弹框
const showDetail = ref<boolean>(false);

// ref
const tableRef = ref(null);

/**
 * 点击查询
 * @author: nxy
 * @Date: 2022-10-12 09:38:18
 */
const reload = () => {
  checkedKeys.value = [];
  tableRef.value.reload({ page: 1 });
};

/**
 * 点击重置
 * @author: nxy
 * @Date: 2022-10-12 09:38:29
 */
const reset = () => {
  where.tipOffReason = '';
  where.custNo = '';
  where.agentNo = '';
  reload();
};

/**
 * 打开详情窗口
 *
 */
const openDetail = async (row: any) => {
  console.log('row', row);
  current.value = await AiAgentApi.detail({ agentNo: row.agentNo });
  showDetail.value = true;
};
</script>
